Linux 免密登录的简便方法

2021年8月4日 2079点热度 1人点赞 0条评论
内容纲要

为了配置 Linux 免密登录,之前找到方法都是比较麻烦的,后面发现一种只需要两个步骤就能完成免密登录配置的方法。

假如,在 Linux A 免密登录 Linux B。
那么在 A 上生成 私钥公钥:

ssh-keygen

生成后,将公钥推送到 B 中:

 ssh-copy-id <user>@<ip>

接着输入免密

然后会提示:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.111 (192.168.0.111)' can't be established.
ECDSA key fingerprint is SHA256:I0oyroOY3138C6+FTfbTPwqQYCuREc2lRHnSheRE3y8.
ECDSA key fingerprint is MD5:4f:bd:c5:b1:02:fd:a3:4b:14:08:be:47:b3:b5:2d:b5.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
afas@192.168.0.111's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'afas@192.168.0.111'"
and check to make sure that only the key(s) you wanted were added.

之后就可以直接免密登录了。

可以在 ~/home/.ssh 命令下看到生成的密钥文件。

* authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥(初始不存在该文件) *
* id_rsa : 生成的私钥文件 *
* id_rsa.pub : 生成的公钥文件*
* know_hosts : 已知的主机公钥清单*

痴者工良

高级程序员劝退师

文章评论